package com.example.interceptor;

import jdk.internal.org.objectweb.asm.Handle;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 用来拦截没有登录的请求
 */
public class UserInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("**");
        if(request.getSession().getAttribute("user")==null){
            return false;
        }else{
            return true;
        }
    }
}
